<?php

namespace App\Models;

use Dcat\Admin\Traits\HasDateTimeFormatter;

use Illuminate\Database\Eloquent\Model;

class Picture extends Model
{

	use HasDateTimeFormatter;

    protected $table = 'picture';

    // 输出时间戳格式
    protected $casts = [
        'created_at' => 'timestamp',
        'updated_at' => 'timestamp',
    ];

    // 追加到模型数组表单的访问器
    protected $appends = ['http_url'];

    // 图片地址拼接域名前缀
    public function getHttpUrlAttribute()
    {
        return $this->url ? config('filesystems.disks.public.url') . $this->url : null;
    }

    public function getList($where = [], $select = ['*'])
    {
        return $this->newQuery()
            ->select($select)
            ->where($where)
            ->orderBy('sort')
            ->limit(5)
            ->get()
            ->toArray();
    }



}
